<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"
    import="java.sql.*"
    import="java.util.Calendar"
    import="java.util.Date"
    import="java.text.DateFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>填寫違規紀錄</title>
</head>

<body>
<% if(session.getAttribute("access") == "y" ){%>
<jsp:useBean id="mydb" scope="page" class="bean.ConDbBean"/> <%//連結資料庫的bean %>
<jsp:useBean id="p_state" scope="page" class="bean.StateBean"/>
<table width="750" border="0" align="center">
  <tr>
    <td width="30" rowspan="4"><jsp:include page="../frameset/left.jsp" flush="true" ></jsp:include></td>
    <td colspan="2"><jsp:include page="../frameset/top.jsp" flush="true" ></jsp:include></td>
    <td width="40" rowspan="4"><jsp:include page="../frameset/right.jsp" flush="true" ></jsp:include></td>
  </tr>
  <tr>
    <td rowspan="2"><jsp:include page="../frameset/mean.jsp" flush="true" ></jsp:include>

    </td>
    <td height="32"><jsp:include page="../frameset/return_mean.jsp" flush="true" ></jsp:include></td>
  </tr>
  <tr>
    <td>
    <%--內頁--%>
    <%
    String date=""; 
    Calendar cal =Calendar.getInstance(); 
	String y1 = ""; //查詢開始年份 
   	String m1 = ""; //查詢開始月份 
   	String d1 = ""; //查詢開始日期 
    y1 = String.valueOf(cal.get(cal.YEAR)); 
    m1=String.valueOf(cal.get(cal.MONTH)+1); 
    d1 =String.valueOf(cal.get(cal.DATE));
    date=y1+"/"+m1+"/"+d1;
    String pfname = new String(request.getParameter("pf_name").getBytes("iso-8859-1"),"utf-8");
	
    %>
    <form action="do_return.jsp" method="post">
     <table width="400" border="0" align="center">
  <tr>
    <td colspan="2" bgcolor="#CC99CC"><div align="center">歸還確認清單</div></td>
  </tr>
  <tr>
    <td width="30%">借用者</td>
    <td width="70%"><%=request.getParameter("m_id") %><input type="hidden" name="m_id" value="<%=request.getParameter("m_id")%>"></td>
  </tr>
  <tr>
    <td width="30%">場地/設備編號</td>
    <td width="70%"><%=request.getParameter("pf_id")%><input type="hidden" name="pf_id" value="<%=request.getParameter("pf_id")%>"></td>
  </tr>
  <tr>
    <td width="30%">名稱</td>
    <td width="70%"><%=pfname%></td>
  </tr>
  <tr>
    <td width="30%">應歸還日期</td>
    <td width="70%"><%=request.getParameter("must_rd")%></td>
  </tr>
  <tr>
    <td width="30%">歸還日期</td>
    <td width="70%"><%=date %></td>
  </tr>
  <tr>
    <td width="30%">逾期天數</td>
    <td width="70%">
    <%
    	String sql="";
    	ResultSet rs;
    	int delay_day=0;
    	sql="select * from DELAY WHERE PF_ID='"+request.getParameter("pf_id")+"'";
		rs=mydb.executeQuery(sql);
		if(rs.next()){
			Date must_return_date = rs.getDate("MUST_RETURN_DATE");
			Date return_date=new Date();
			Calendar day1 = Calendar.getInstance();
			Calendar day2 = Calendar.getInstance();
    		day1.setTime(return_date);
    		day2.setTime(must_return_date);
    		int a = day1.get(day1.DAY_OF_YEAR);
    		int b = day2.get(day2.DAY_OF_YEAR);
    		delay_day  = a-b ;
    		
		}
		out.print(delay_day);
     %>
    天
    <input type="hidden" name="delay_day" value="<%=delay_day%>">
    </td>
  </tr>
  <%
  //去讀取系統的罰款金額
  		sql="select S_VALUE from SYS_SETTING WHERE S_NAME='fine_day'";
		rs=mydb.executeQuery(sql);
		rs.next();
		int money=java.lang.Integer.valueOf(rs.getString("S_VALUE"));
   %>
  <tr>
    <td width="30%">罰款金額</td>
    <td width="70%"><%out.print(delay_day*money+"$(逾期一天罰款"+money+"元)"); %></td>
  </tr>
  <tr>
    <td>是否毀損</td>
    <td><input name="bad" type="radio" value="0" checked="checked" />否
	<input name="bad" type="radio" value="1" />是</td>
  </tr>
  <tr>
    <td colspan="2"><br/></td>
  </tr>
  <tr>
    <td colspan="2"><div align="center">
      <input type="reset" name="Submit" value="重新填寫" />
      <input type="submit" name="Submit2" value="確定" />
    </div></td>
  </tr>
</table></form>
<%--內頁end--%>
    </td>
  </tr>
  <tr>
    <td colspan="2"></td>
  </tr>
</table>
<%
  }
  else{
  	response.sendRedirect("../index.jsp"); //若沒有登入則回到index.jsp
  } 
  %>

</body>
</html>
